package com.gorkr.labuladong.data_struct.array;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @author gorkr
 * @date 2022/06/04 11:10
 **/
public class M48RotateImage {

    public void rotate(int[][] matrix) {
        int n = matrix.length;
        int tmp;
        // 对角线堆成
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                tmp = matrix[i][j];
                matrix[i][j] = matrix[j][i];
                matrix[j][i] = tmp;
            }
        }
        int i = 0;
        int j = n-1;
        // 每一行反转
        for (int k = 0; k < n; k++) {
            while (i < j) {
                tmp = matrix[k][i];
                matrix[k][i] = matrix[k][j];
                matrix[k][j] = tmp;
                i++;
                j--;
            }
            i = 0;
            j = n-1;


        }
    }

    @Test
    public void test(){
        int[][] matrix = {
                {1,2,3},
                {4,5,6},
                {7,8,9}
        };
        rotate(matrix);


    }
}
    